package com.qezhhnjy.huawei.zhaoyin;

import java.util.Arrays;

public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param nums   int整型一维数组
     * @param values int整型一维数组
     * @return int整型
     */
    public int getMaxValue(int[] nums, int[] values) {
        return max(nums, values, 0, nums.length - 1, 0);
    }

    public int max(int[] nums, int[] values, int left, int right, int count) {
        if (left == right) return nums[left] * values[count];
        int first = nums[left] * values[count] + max(nums, values, left + 1, right, count + 1);
        int second = nums[right] * values[count] + max(nums, values, left, right - 1, count + 1);
        return Math.max(first, second);
    }

    public int max(int[] nums, int[] values, int numsLeft, int numsRight, int valuesLeft, int valuesRight) {
        if (numsLeft == numsRight) return nums[numsLeft] * values[valuesLeft];
        int first = nums[numsLeft] * values[valuesLeft] + max(nums, values, numsLeft + 1, numsRight, valuesLeft + 1, valuesRight);
        int second = nums[numsRight] * values[valuesRight] + max(nums, values, numsLeft, numsRight - 1, valuesLeft, valuesRight - 1);
        int third = nums[numsLeft] * values[valuesRight] + max(nums, values, numsLeft + 1, numsRight, valuesLeft, valuesRight - 1);
        int forth = nums[numsRight] * values[valuesLeft] + max(nums, values, numsLeft, numsRight - 1, valuesLeft + 1, valuesRight);
        return Math.max(Math.max(first, second), Math.max(third, forth));
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param arrA int整型一维数组
     * @param K    int整型
     * @return int整型一维数组
     */
    public int[] tranArr(int[] arrA, int K) {
        // write code here

        Arrays.sort(arrA);
        int minA = arrA[0];
        int maxA = arrA[arrA.length - 1];
        int[] result = new int[2];
        result[0] = Math.min(maxA - K, minA + K);
        result[1] = maxA - K;
        return result;
    }

    public static void main(String[] args) {

        System.out.println(new Solution().getMaxValue(new int[]{1, 100}, new int[]{2, 1}));
        System.out.println(new Solution().getMaxValue(new int[]{1, 3, 5, 2, 4}, new int[]{1, 2, 3, 4, 5}));
    }
}